//
//  ClickRightCornerJumpToViewController.m
//  NewChat
//
//  Created by lanou3g on 16/2/29.
//  Copyright © 2016年 蓝鸥. All rights reserved.
//

#import "ClickRightCornerJumpToViewController.h"
#import "UIView+SDAutoLayout.h"
#import "TopicTableViewCell.h"
#import "LReplyTableViewCell.h"
#import "ReplyViewController.h"
#import "PersonalHomePageTableViewController.h"


@interface ClickRightCornerJumpToViewController ()

//用来设置导航栏
@property(nonatomic,strong)UISegmentedControl*segment;
//用来记录当前选择的segment
@property(nonatomic,assign)NSUInteger index;

@end

@implementation ClickRightCornerJumpToViewController

-(instancetype)initWithStyle:(UITableViewStyle)style{
    
    if (self = [super initWithStyle:UITableViewStylePlain]) {
        
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    //隐藏底部tabbar
    self.tabBarController.tabBar.hidden = YES;
    
    NSLog(@"这个页面是ClickRightCornerJumpToViewController");
    
}

static NSString*identifier = @"LReplyCell";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSLog(@"这个页面是ClickRightCornerJumpToViewController");
    self.view.backgroundColor = [UIColor whiteColor];
    
    //注册cell
    [self.tableView registerClass:[TopicTableViewCell class] forCellReuseIdentifier:@"TCell"];
    UINib *replyNib = [UINib nibWithNibName:@"LReplyTableViewCell" bundle:[NSBundle mainBundle]];
    [self.tableView registerNib:replyNib forCellReuseIdentifier:identifier];

    NSArray *string = @[@"主题",@"收藏",@"回复"];
    self.segment = [[UISegmentedControl alloc]initWithItems:string];
    self.segment.tintColor = [UIColor whiteColor];
    //设置默认选中的下标
    self.segment.selectedSegmentIndex = 0;
    //设置选中的状态
    self.segment.momentary = NO;
    //设置高和宽
    self.segment.sd_layout.heightIs(35).widthIs([UIScreen mainScreen].bounds.size.width*0.6);
    self.segment.multipleTouchEnabled = YES;
    self.navigationItem.titleView = self.segment;
    //添加事件
    [self.segment addTarget:self action:@selector(clickSegmentControlAction:) forControlEvents:UIControlEventValueChanged];
    
}


-(void)clickSegmentControlAction:(UISegmentedControl*)sender{
    //将当前segment的下标赋给index，用于根据不同segment创建不同的cell
    self.index = sender.selectedSegmentIndex;
    NSLog(@"........................%lu",self.index);
    [self.tableView reloadData];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    
    
    return 5;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {


    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    
        //根据 当前segment的下标 加载对应的cell
         if (self.index == 2){
        
         LReplyTableViewCell*lreplyCell = [tableView dequeueReusableCellWithIdentifier:identifier];
             
        lreplyCell.userPictureImV.image = [UIImage imageNamed:@"55.png"];
        [lreplyCell.userBtn addTarget:self action:@selector(ClickUserPictureBtn:) forControlEvents:(UIControlEventTouchDown)];
            return lreplyCell;
             
        }

        TopicTableViewCell *Topcell = [tableView dequeueReusableCellWithIdentifier:@"TCell"];
    
        Topcell = [[TopicTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TCell"];
        Topcell.nickNameLbl.text = @"哎呦呦";
        Topcell.timeLbl.text = @"10分钟前";
        Topcell.topicLbl.text = @"你会不会因为声音就喜欢上TA";
        [Topcell.messageBtn setTitle:@"1024回复" forState:(UIControlStateNormal)];
        [Topcell.userPictureBtn setBackgroundImage:[UIImage imageNamed:@"55.png"] forState:(UIControlStateNormal)];
        [Topcell.userPictureBtn addTarget:self action:@selector(ClickUserPictureBtn:) forControlEvents:(UIControlEventTouchDown)];
        //设置voiceBtn上的文字距离左侧140个像素
        [Topcell.voiceBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 140, 0, 0)];
        [Topcell.voiceBtn setTitle:@"10\"" forState:(UIControlStateNormal)];
        [Topcell.voiceBtn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];

            
            return Topcell;

    
}




-(void)ClickUserPictureBtn:(UIButton*)sender{
    PersonalHomePageTableViewController*perVC = [[PersonalHomePageTableViewController alloc]init];
    NSLog(@"这是TopicTableViewCell子控件的点击事件");
    [self.navigationController pushViewController:perVC animated:YES];
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //根据segment的下标选择不同高度满足需要
    if (self.index == 2) {
        
        return self.view.frame.size.height/3.5;
        
    }else{
        
        return self.view.frame.size.height/3.8;

    }
    
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    NSLog(@"你点击了ClickRightCornerJumpToViewController中的cell");
    NSLog(@"即将跳转到的页面是:发现 ——> ReplyViewController");
    ReplyViewController*replyVC = [[ReplyViewController alloc]init];
    [self.navigationController pushViewController:replyVC animated:YES];
    
    
}




/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
